<%@ page import="com.malethan.seemorej.SeemoreJ" %>
<%@ page import="com.malethan.seemorej.Flash" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<#assign pojoNameLower = util.getLowerCaseFirstLetter(pojo.shortName)>
<#assign pojoNamePlural = util.getPluralForWord(pojoNameLower)>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sj" uri="http://java.malethan.com/seemorej/taglib/seemorej.tld" %>

<c:set var="timestampPattern" value="EEE, d MMM yyyy HH:mm:ss z" />
<c:set var="datePattern" value="EEE, d MMM yyyy" />
<c:set var="timePattern" value="HH:mm:ss" />

<html>
<head>
    <title>Showing ${util.humaniseCamelCase(pojo.shortName)} #<c:out value="${'$'}{${pojoNameLower}.${pojo.getIdentifierProperty().name}}" /></title>
</head>
<body>

<c:set var="success"><%=SeemoreJ.flash(Flash.SUCCESS)%></c:set>
<c:if test="${'$'}{!empty(success) && success != 'null'}">
    <div class="success">
        <p><c:out value="${'$'}{success}" /></p>
    </div>
</c:if>

<c:set var="notice"><%=SeemoreJ.flash(Flash.NOTICE)%></c:set>
<c:if test="${'$'}{!empty(notice) && notice != 'null'}">
    <div class="notice">
        <p><c:out value="${'$'}{notice}" /></p>
    </div>
</c:if>

<c:set var="error"><%=SeemoreJ.flash(Flash.ERROR)%></c:set>
<c:if test="${'$'}{!empty(error) && error != 'null'}">
    <div class="error">
        <p><c:out value="${'$'}{error}" /></p>
    </div>
</c:if>

<table>
    <#foreach field in pojo.getAllPropertiesIterator()>
        <#if !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)>
            <#lt/>    <tr>
            <#lt/>        <th> ${util.humaniseCamelCase(field.name)}</th>
            <#lt/>        <td>
            <#if field.value.typeName == "date" || field.value.typeName == "time" || field.value.typeName == "timestamp">
                    <#lt/>            <fmt:formatDate value="${'$'}{${pojoNameLower}.${field.name}}" pattern="${'$'}{${field.value.typeName}Pattern}"/>
            <#elseif field.value.typeName == "boolean" || field.value.typeName == "java.lang.Boolean">
                <#lt/>            <input type="checkbox" disabled="disabled" <c:if test="${'$'}{${pojoNameLower}.${field.name}}">checked="checked"</c:if>/>
            <#else>
                <#lt/>            <c:out value="${'$'}{${pojoNameLower}.${field.name}}" />
            </#if>
            <#lt/>        </td>
            <#lt/>    </tr>
        </#if>
    </#foreach>
</table>

<%-- TODO: use something more concise to generate URLs --%>
<c:set var="listUrl">
  <c:url value="/seemore">
    <c:param name="sjController" value="${'$'}{param.sjController}" />
    <c:param name="sjAction" value="list" />
    <c:param name="sjFormat" value="html" />
  </c:url>
</c:set>

<c:set var="editUrl">
  <c:url value="/seemore">
    <c:param name="sjController" value="${'$'}{param.sjController}" />
    <c:param name="sjAction" value="edit" />
    <c:param name="id" value="${'$'}{${pojoNameLower}.${pojo.getIdentifierProperty().name}}" />
    <c:param name="sjFormat" value="html" />
  </c:url>
</c:set>

<c:set var="deleteUrl">
  <c:url value="/seemore">
    <c:param name="sjController" value="${'$'}{param.sjController}" />
    <c:param name="sjAction" value="delete" />
    <c:param name="id" value="${'$'}{${pojoNameLower}.${pojo.getIdentifierProperty().name}}" />
    <c:param name="sjFormat" value="html" />
  </c:url>
</c:set>

<p>
    <a href="${'$'}{listUrl}">&laquo; Back</a> &bull;
    <a href="${'$'}{editUrl}">Edit</a> &bull;
    <a href="#" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = '${'$'}{deleteUrl}';var m = document.createElement('input');f.submit(); };return false;">Delete</a>
</p>
</body>
</html>